package com.juttec.freshbird.pet.base.zixunbasetab;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.juttec.freshbird.pet.R;
import com.juttec.freshbird.pet.ZixunContentActivity;
import com.juttec.freshbird.pet.base.BasePager;
import com.juttec.freshbird.pet.base.BaseTab;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * Created by Administrator on 2015/10/28.
 */
public class ZixunRestTab extends BaseTab {
    private ListView mListView;

    //通过注入的listview设置适配器的时候，会报出空指针异常
    //所以不能使用注入获取listview
//    @ViewInject(R.id.lv_zixun_rest_tab)
//    public ListView mListView;
    public ZixunRestTab(Activity activity) {
        super(activity);
    }

    @Override
    public View initViews() {
        View view = View.inflate(mActivity, R.layout.zixun_rest_tab, null);
        mListView = (ListView) view.findViewById(R.id.lv_zixun_rest_tab);
        ViewUtils.inject(view);
        mListView.setAdapter(new lvZixunRestTabAdapter());
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(mActivity, ZixunContentActivity.class);
                mActivity.startActivity(intent);
            }
        });
        return view;
    }

    @Override
    public void initData() {
        super.initData();

    }

    class lvZixunRestTabAdapter extends BaseAdapter {

        private BitmapUtils mUtils;

        public lvZixunRestTabAdapter(){
            mUtils = new BitmapUtils(mActivity);
//            mUtils.configDefaultLoadingImage(R.drawable.com_54);
        }

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = View.inflate(mActivity,R.layout.zixunlated_listview_item,null);
                holder = new ViewHolder();
                holder.ivPic = (ImageView) convertView.findViewById(R.id.iv_pic);
                holder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
                holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
                holder.tvRedu = (TextView) convertView.findViewById(R.id.tv_redu);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
//            holder.tvTitle.setText("");
//            holder.tvDate.setText("");
//            holder.tvRedu.setText("");
//            mUtils.display(holder.ivPic,"");
            return convertView;
        }
    }

    static class ViewHolder {
        public ImageView ivPic;
        public TextView tvTitle;
        public TextView tvDate;
        public TextView tvRedu;
    }

}
